#pragma once

#include "StrategyFactory.hpp"
#include <memory>
#include <stdexcept>
#include <vector>
class BestFactory : public StrategyFactory{
public:
    explicit BestFactory(std::vector<std::unique_ptr<StrategyFactory>>&& factories)
            : m_factories(std::move(factories))
            {
                if(m_factories.empty()){
                    throw std::runtime_error{"No factory"};
                }
            }
protected:
    std::unique_ptr<IWriteStrategy> createStrategy() override
    {
        StrategyFactory* bestSoFar{m_factories[0].get()};
        for(auto &factory : m_factories){
            if(factory->getNumberProduced() < bestSoFar->getNumberProduced()){
                bestSoFar = factory.get();
            }
        }
        return bestSoFar->requestStrategy();
    }
private:
    std::vector<std::unique_ptr<StrategyFactory>> m_factories;
};